<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>书籍管理</title>
<%@ include file="/base/jsp/include.jsp"%>
</head>
<body>
	<div class="mini-toolbar" style="padding:2px;border-bottom:0;">
		<table style="width:100%;">
			<tr>
				<td style="width:100%;"><a class="mini-button"
					iconCls="icon-add" plain="true" onclick="addRow()">添加</a> <span
					class="separator"></span> <a class="mini-button"
					iconCls="icon-edit" plain="true" onclick="edit()">修改</a> <span
					class="separator"></span> <a class="mini-button"
					iconCls="icon-remove" plain="true" onclick="del()">删除</a><span
					class="separator"></span><a class="mini-button"
					iconCls="icon-cancel" plain="true" href="javascript:clearFilter()">清除筛选</a></td>
			</tr>
		</table>
	</div>
	<!--撑满页面-->
	<div class="mini-fit">
		<div id="grid" class="mini-datagrid" style="width:100%;height:100%;"
			pageSize="20" borderStyle="border:1;" url="sortByOrder.do" idField="id"
			multiSelect="true" showFilterRow="true">
			<div property="columns">
				<div type="checkcolumn" field="imgId"></div>
				<div type="indexcolumn" headerAlign="center">序号</div>
				<div field="isbn" width="50" headerAlign="center" align="center">ISBN号</div>
				<div field="name" width="50" headerAlign="center" align="center">名称</div>
				<div field="author" width="50" headerAlign="center" align="center">作者</div>
				<div field="publisher" width="50" headerAlign="center" align="center">出版社</div>	
				<div field="oCount" width="50" headerAlign="center" align="center">销量</div>		
				<div field="reportory" width="50" headerAlign="center" align="center">库存</div>
				<div field="priceSelling" width="50" headerAlign="center" align="center">售价</div>
				<div field="priceOriginal" width="50" headerAlign="center" align="center">原价</div>
				<div field="isHot" width="50" headerAlign="center" align="center" renderer="hotBtn">是否置为热卖</div>
				<div field="img" width="100" headerAlign="center" align="center"  renderer="pictureHandler">显示图片</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	var name='', author='', publisher='';
	mini.parse();
	var grid = mini.get("grid");
	grid.load();
	function addRow() {
		mini.open({
			url : "toEditBook.do",
			title : "首页图片新增",
			width : 800,
			height : 600,
			onload : function() {
				var iframe = this.getIFrameEl();
				var data = {
					action : "new"
				};
				iframe.contentWindow.SetData(data);
			},
			ondestroy : function(action) {
				grid.reload();
			}
		});
	}

	function del() {
		var rows = grid.getSelecteds();
		if (rows.length > 0) {
			mini.confirm("确定删除吗？", "确定？", function(action) {
				if (action == "ok") {
					var ids = [];
					for ( var i = 0, l = rows.length; i < l; i++) {
						var r = rows[i];
						ids.push(r.id);
					}
					var id = ids.join(',');
					grid.loading("操作中，请稍后......");
					$.ajax({
						url : "delBook.do?id=" + id,
						success : function(text) {
							grid.reload();
						},
						error : function() {
						}
					});
				}
			});
		} else {
			mini.alert("请选中一条记录");
		}
	}
	
	function hotBtn(e) {
		var record = e.record;
            var uid = record.id;
            var s;
            if(e.value == 1) {
            	s = '<a class="New_Button" href="javascript:hotSet(\'' + uid + '\', 0)">取消设置</a> ';
            } else {
            	s = '<a class="New_Button" href="javascript:hotSet(\'' + uid + '\', 1)">置为热卖</a> ';
            }
            return s;
	}
	
	function hotSet(uid, isHot) {
       	mini.confirm("确定操作吗？", "确定？", function(action) {
       		 if(action == "ok") {
       		 	$.ajax({
                   	url: "setHot.do?id=" + uid + "&isHot=" + isHot,
                   	cache: false,
                   	success: function (text) {
                   		if(text.indexOf('true') > -1){
    				    	mini.alert("操作成功");
    				    	grid.load();
    				    }else{
    				    	mini.alert("操作失败");
    				    }
                  		},
                  		error: function (jqXHR, textStatus, errorThrown) {
                  			mini.alert("操作失败");
                   	}
               	});
       		 }
       	});
       }

	function edit() {
		var rows = grid.getSelecteds();
		if (rows.length == 1) {
			var row = grid.getSelected();
			mini.open({
				url : "toEditBook.do",
				title : "书籍编辑",
				width : 800,
				height : 600,
				onload : function() {
					var iframe = this.getIFrameEl();
					var data = {
						action : "edit",
						id : row.id
					};
					iframe.contentWindow.SetData(data);
				},
				ondestroy : function(action) {
					grid.reload();
				}
			});
		} else if (rows.length > 1) {
			mini.alert("只能选一条记录");
		} else {
			mini.alert("请选中一条记录");
		}

	}
	
	function onFilterChanged() {
       var namebox = mini.get("nameFilter");
       var authorbox = mini.get("authorFilter");
       var publisherbox = mini.get("publisherFilter");
       
       name = namebox.getValue().toLowerCase();
       author = authorbox.getValue().toLowerCase();
       publisher = publisherbox.getValue().toLowerCase();
       grid.load({name: name, author : author, publisher : publisher});
   }
	
	function clearFilter() {
	   var namebox = mini.get("nameFilter");
	   var authorbox = mini.get("authorFilter");
	   var publisherbox = mini.get("publisherFilter");
	   name = '';
       author = '';
       publisher = '';
	   namebox.setValue("");
	   authorbox.setValue("");
	   publisherbox.setValue("");
       grid.load();
   }
</script>
</html>
